import {patchZero} from "@/utils";

export const generateProject = (list) => {
    if (!list || !list.length) return []
    return list.map(item => {
        const {start_date, end_date, day} = item
        item.startDate = getDate(start_date)
        item.endDate = getDate(end_date)
        let dayText = '',
            dayStatus = 0;
        if (day === null) {
            dayText = '已完成'
        } else if (day >= 0) {
            dayText = `剩余${day}天`
            dayStatus = 2
        } else {
            dayText = `延期${Math.abs(day)}天`
            dayStatus = 1
        }
        const statusEnum = {
            '0': 'success',
            '1': 'danger',
            '2': ''
        }
        item.tagStatus = statusEnum[dayStatus]
        item.dayText = dayText
        item.dayStatus = dayStatus
        return item
    })

}

export function getDate(dateStr) {
    const date = new Date(dateStr)
    const [month, day] = [date.getMonth() + 1, date.getDate()]
    return `${patchZero(month)}/${patchZero(day)}`
}
